<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:insert="~{include :: header('岗位列表')}" />
	<th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
	<div class="toolbar" id="toolbar" role="group">
		<form id="formId">
			<div class="form-inline">
				<a class="btn btn-success mr-1" onclick="$.operate.add()" shiro:hasPermission="post:add">
					<i class="fa fa-plus"></i> 新增
				</a>
				<input type="text" class="form-control mr-1" name="searchKey" placeholder="岗位名称">
				<button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
					<i class="fa fa-search"></i>
					搜索
				</button>
				<button type="button" class="btn btn-default" onclick="$.form.reset()">
					<i class="fa fa-refresh"></i>
					重置
				</button>
			</div>
		</form>
	</div>
	<table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
	var editFlag = [[${@permission.hasPermi('post:edit')}]];
	var removeFlag = [[${@permission.hasPermi('post:remove')}]];
	var datas = [[${@dict.getType('sys_normal_disable')}]];
	var prefix = "/post";

	$(function() {
		var options = {
			showSearch: false,
			showRefresh: false,
			showToggle: false,
			showColumns: false,
			url: prefix + "/list.json",
			createUrl: prefix + "/add.html",
			updateUrl: prefix + "/edit.html?id={id}",
			removeUrl: prefix + "/remove.json",
			sortName: "postSort",
			modalName: "岗位",
			columns: [
				{
					field: 'postId',
					title: '岗位编号'
				},
				{
					field: 'postName',
					title: '岗位名称',
					sortable: true
				},
				{
					field: 'postCode',
					title: '岗位编码',
					sortable: true
				},
				{
					field: 'sort',
					align: 'center',
					title: '显示顺序'
				},
				{
					visible: editFlag === 'hidden' ? false : true,
					field: 'isDisabled',
					title: '是否启用',
					align: 'center',
					formatter: function (value, row, index) {
						return disabledTools(row);
					}
				},
				{
					field: 'createTime',
					title: '创建时间',
					sortable: true
				},
				{
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.postId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
					}
				}]
		};
		$.table.init(options);
	});

	/* 岗位状态-显示 */
	function disabledTools(row) {
		if (row.isDisabled === 0) {
			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disabledClose(\'' + row.postId + '\')"></i> ';
		} else {
			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="disabledOpen(\'' + row.postId + '\')"></i> ';
		}
	}

	/* 岗位管理-停用 */
	function disabledClose(postId) {
		$.modal.confirm("确认要停用岗位吗？", function() {
			$.operate.post(prefix + "/status.json", { "postId": postId, "status": 1 });
		})
	}

	/* 岗位管理-启用 */
	function disabledOpen(postId) {
		$.modal.confirm("确认要启用岗位吗？", function() {
			$.operate.post(prefix + "/status.json", { "postId": postId, "status": 0 });
		})
	}
</script>
</body>
</html>